﻿using System;
using System.Collections.Generic;
using System.Text;
using Zhuang.Model.Access;
using Zhuang.Utility.Common.Entity;
using System.Collections;
using Zhuang.Utility.Common.DataBase;
using System.Data;

namespace Zhuang.DAL.Access
{
    public class Pos_SalesOrdersMasterDAL
    {
        public string Add(Pos_SalesOrdersMasterEntity some)
        {
            ArrayList alSql = new ArrayList();

            string strSql = EntityHelper<Pos_SalesOrdersMasterEntity>.GetInsertSql(some);
            alSql.Add(strSql);

            strSql = @"insert into Pos_SalesOrdersDetail(SalesOrdersMasterId, ProductId, ProductName, ProductCode, UnitPrice, Quantity)
            select '{0}',ProductId,ProductName,ProductCode,UnitPrice,Quantity from Pos_CurrentOrder ";
            strSql = string.Format(strSql,some.SalesOrderMasterId);
            alSql.Add(strSql);

            strSql = "delete from Pos_CurrentOrder";
            alSql.Add(strSql);

            OleDbHelper.ExecuteSqlTran(alSql);

            return some.SalesOrderMasterId;
        }

        public DataTable Get(string conditions)
        {
            string strSql =string.Format(@"select * from Pos_SalesOrdersMaster where 1=1 and {0}",conditions);

            return OleDbHelper.Query(strSql).Tables[0];
        }
    }
}
